package com.handinfo.android.ui.window;


import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PointF;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.object.Background;
import com.handinfo.android.core.object.Scene;
import com.handinfo.android.core.object.Scene.SceneHandler;
import com.handinfo.android.game.GameActorConstants;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.SceneNPC;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWExternalDraw;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWCheckbox;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTabControl;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIMap implements IUIWindows {

	public void init() {
		
	}

	public void open(byte index) {
		openWorldMap();
	}

	public void close(byte index) {
		
	}

	public void dispose() {
		
	}

	public void logic() {
		if (m_world_map != null && DWControlsManager.getInstance().contains(m_world_map)) {
			long currentTime = System.currentTimeMillis();
			if (currentTime - m_start_time >= m_update_time) {
				SceneHandler sh = (SceneHandler)DWGameManager.getInstance().getGameHandler();
				m_imagebox_area.setImage(sh.m_scene.m_img_thumbnail);
				m_start_time = System.currentTimeMillis();
				Tools.debugPrintln("更新区域地图图片!");
			}
//			if (m_is_transit && m_percent_bar != null) {
//				m_percent_bar.setShow(true);
//				m_percent_bar.setPercent(m_transit_time, m_transit_length);
//				if (m_transit_time++ >= m_transit_length) {
//					m_is_transit = false;
//					m_percent_bar.setShow(false);
//				}
//			}
		}
	}
	private int m_update_time = 5000;
	private long m_start_time = 0;
	public DWFrame m_world_map = null;
	public DWImageBox m_imagebox_area = null;//本区图片
	public DWListbox m_listbox_npc = null;//NPC列表
	public DWCheckbox m_cb_npc = null;
	public DWCheckbox m_cb_monster = null;
	public DWCheckbox m_cb_interaction = null;
	public DWCheckbox m_cb_portal = null;
	
	public DWImageBox m_imagebox_world = null;//世界图片
	public DWButton m_button_world = null;//返回世界按钮
	private Bitmap m_image_world = null;
	private DWBackground m_bg_left = null;
	private DWBackground m_bg_right = null;
//	private DWPercentBar m_percent_bar = null;//传送读条
	private void openWorldMap() {
		if (m_world_map == null) {
			m_world_map = new DWFrame(DWFrame.FRAME_TYPE_FULL);
			m_world_map.setClickClose(false);
			
			DWTitle title = new DWTitle("", m_world_map);
			m_world_map.addControl(title);
			DWImageBox m_tit_ima  = new DWImageBox(UIWindows.createImage("/img/newui/ditu_1.gnp"));
			m_tit_ima.setNearAnchor(title, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
			m_world_map.addControl(m_tit_ima);
			
			DWImageBox ib_tc = new DWImageBox(UIWindows.createImage("/img/newui/fanhuianniu_1.gnp"));
			ib_tc.setNearAnchor(title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
			ib_tc.setTouchZoomIn(20, 20);
			ib_tc.addListener(new DWListener() {
				public void OnDoubleClick() {
				}
				public void OnClick() {
					DWControlsManager.getInstance().removeControl(m_world_map);
				}
			});
			m_world_map.addControl(ib_tc);
			
			//大背景
			DWBackground bg_big = new DWBackground(m_world_map.getShowWidth() - 20, m_world_map.getShowHeight() - title.getShowHeight() - 47);
			bg_big.setFill(true);
			bg_big.setNearAnchor(title, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 10, 37);
			m_world_map.addControl(bg_big);
			//左背景
			m_bg_left = new DWBackground(bg_big.getShowWidth() / 3 * 2 - 20, bg_big.getShowHeight() - 20);
			m_bg_left.setFill(true);
			m_bg_left.setNearAnchor(bg_big, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
			m_world_map.addControl(m_bg_left);
			//右背景
			m_bg_right = new DWBackground(bg_big.getShowWidth() / 3 - 10, bg_big.getShowHeight() - 20);
			m_bg_right.setFill(true);
			m_bg_right.setNearAnchor(bg_big, Tools.RIGHT_TOP, Tools.RIGHT_TOP, -10, 10);
			m_world_map.addControl(m_bg_right);
			
			//标签页
			final DWTabControl tabControl = new DWTabControl(UIWindows.createImage("/img/newui/biaoqianye_1.gnp"),
					UIWindows.createImage("/img/newui/biaoqianye_2.gnp"),
					bg_big.getShowWidth() - 20, bg_big.getShowHeight() + 37);
			tabControl.setNearAnchor(bg_big, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, -37);
			tabControl.addListener(new DWListener() {
				public void OnDoubleClick() {
				}
				public void OnClick() {
					int index = tabControl.getPageIndex();
					if (index == 0) {
						m_bg_left.setShow(true);
						m_bg_right.setShow(true);
					} else {
						m_bg_left.setShow(false);
						m_bg_right.setShow(false);
					}
				}
			});
			
			//本区页
			DWTabPage tabPage_area = new DWTabPage();
			tabPage_area.setName("本区");
			
			//本区图片容器
			SceneHandler sh = (SceneHandler)DWGameManager.getInstance().getGameHandler();
			m_imagebox_area = new DWImageBox(sh.m_scene.m_img_thumbnail);
			m_imagebox_area.setAutoFill(false);
			m_imagebox_area.setActualWideHigh(m_imagebox_area.getShowWidth(), m_imagebox_area.getShowHeight());
			m_imagebox_area.setShowWideHigh(m_bg_left.getShowWidth() - 20, m_bg_left.getShowHeight() - 20);
			m_imagebox_area.setNearAnchor(tabPage_area, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 20);
			m_imagebox_area.addExternalDraw(m_ed_area);
			m_imagebox_area.addListener(m_lis_area);
			tabPage_area.addControls(m_imagebox_area);
			
			//类型选区背景
			DWBackground bg_select = new DWBackground(UIWindows.createImage("/img/newui/beibaobj_1.gnp"),
					m_bg_right.getShowWidth(), m_bg_right.getShowHeight() / 3);
			bg_select.setNearAnchor(tabPage_area, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 10);
			tabPage_area.addControls(bg_select);
			
			//NPC选签
			m_cb_npc = new DWCheckbox();
			m_cb_npc.setChecked(true);
			m_cb_npc.setNearAnchor(bg_select, Tools.RIGHT_BOTTOM, Tools.HCENTER_VCENTER, -5, 0);
			tabPage_area.addControls(m_cb_npc);
			
			DWLabel l_npc = new DWLabel("NPC");
			l_npc.setShowBackground(false);
			l_npc.setNearAnchor(m_cb_npc, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			tabPage_area.addControls(l_npc);
			
			//怪物选签
			m_cb_monster = new DWCheckbox();
			m_cb_monster.setNearAnchor(bg_select, Tools.RIGHT_TOP, Tools.HCENTER_VCENTER, -5, 10);
			tabPage_area.addControls(m_cb_monster);
			
			DWLabel l_monster = new DWLabel("怪物");
			l_monster.setShowBackground(false);
			l_monster.setNearAnchor(m_cb_monster, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			tabPage_area.addControls(l_monster);
			
			//互动
			m_cb_interaction = new DWCheckbox();
			m_cb_interaction.setNearAnchor(bg_select, Tools.RIGHT_BOTTOM, Tools.RIGHT_VCENTER, 0, 0);
			tabPage_area.addControls(m_cb_interaction);
			
			DWLabel l_interaction = new DWLabel("互动");
			l_interaction.setShowBackground(false);
			l_interaction.setNearAnchor(m_cb_interaction, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			tabPage_area.addControls(l_interaction);
			
			//传送门
			m_cb_portal = new DWCheckbox();
			m_cb_portal.setNearAnchor(bg_select, Tools.RIGHT_TOP, Tools.RIGHT_VCENTER, 0, 10);
			tabPage_area.addControls(m_cb_portal);
			
			DWLabel l_portal = new DWLabel("传送门");
			l_portal.setShowBackground(false);
			l_portal.setNearAnchor(m_cb_portal, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, 0, 0);
			tabPage_area.addControls(l_portal);
			
			//NPC列表背景
			DWBackground bg_npc = new DWBackground(UIWindows.createImage("/img/newui/beibaobj_1.gnp"),
					m_bg_right.getShowWidth(), m_bg_right.getShowHeight() / 3 * 2 - 10);
			bg_npc.setNearAnchor(bg_select, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10);
			tabPage_area.addControls(bg_npc);
			
			//NPC列表
			m_listbox_npc = new DWListbox(bg_npc.getShowWidth() - 35, bg_npc.getShowHeight() - 20);
			m_listbox_npc.setNearAnchor(bg_npc, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
			for (int i = 0; i < m_scene_npc.size(); i++) {
				SceneNPC npc = m_scene_npc.get(i);
				DWListSubItem lsi = new DWListSubItem();
				DWTextbox tb = new DWTextbox(npc.m_name);
				tb.setNearAnchor(lsi, Tools.LEFT_TOP, Tools.LEFT_TOP);
				lsi.addControls(tb);
				m_listbox_npc.addSubItem(lsi);
			}
			m_listbox_npc.addListener(m_npc_list);
			tabPage_area.addControls(m_listbox_npc);
			
			tabControl.addTabPage(tabPage_area);
			
			//世界页
			DWTabPage tabPage_world = new DWTabPage();
			tabPage_world.setName("世界");
			
			m_image_world = UIWindows.createImage("/img/newui/shijieditu_1.gnp");
			m_imagebox_world = new DWImageBox(m_image_world);
			m_imagebox_world.setNearAnchor(tabPage_world, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 20);
			m_imagebox_world.addExternalDraw(m_ed_world);
			m_imagebox_world.addListener(m_lis_world);
			tabPage_world.addControls(m_imagebox_world);
			
			m_button_world = new DWButton("", UIWindows.createImage("/img/newui/shijie_1.gnp"));
			m_button_world.setDownImage(UIWindows.createImage("/img/newui/shijie_2.gnp"));
			m_button_world.setNearAnchor(m_imagebox_world, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 10, -10);
			m_button_world.setShow(false);
			m_button_world.setTouch(false);
			m_button_world.addListener(m_lis_button);
			tabPage_world.addControls(m_button_world);
			
			tabControl.addTabPage(tabPage_world);
			m_world_map.addControl(tabControl);
		}
		if (m_imagebox_area != null) {
			Role role = DWGameManager.getInstance().m_role;
			m_imagebox_area.setImageShift(role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO, role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO);
		}
		
		if (m_imagebox_world != null) {
			if (m_is_area) {
				m_is_area = false;
				m_button_world.setShow(false);
				m_button_world.setTouch(false);
				m_imagebox_world.setImage(UIWindows.createImage("/img/newui/shijieditu_1.gnp"));
				UIWindows.removeImage("/img/newui/" + WORLD_IMAGE[m_area_index] + ".gnp");
			}
		}
		DWControlsManager.getInstance().addControl(m_world_map);
	}
	private DWListener m_npc_list = new DWListener() {
		public void OnDoubleClick() {}
		public void OnClick() {
			if (m_listbox_npc != null) {
				int index = m_listbox_npc.getTouchIndex();
				SceneNPC npc = m_scene_npc.get(index);
				if (npc != null) {
					openFindPath(npc.m_x, npc.m_y);
				}
			}
		}
	};
	private DWListener m_lis_area = new DWListener() {
		public void OnDoubleClick() {
		}
		public void OnClick() {
			openFindPath(m_imagebox_area.getClickX(), m_imagebox_area.getClickY());
		}
	};
	
	/**
	 * 返回世界按钮
	 */
	private DWListener m_lis_button = new DWListener() {
		public void OnDoubleClick() {
		}
		public void OnClick() {
			m_is_area = false;
			m_button_world.setShow(false);
			m_button_world.setTouch(false);
			m_imagebox_world.setImage(UIWindows.createImage("/img/newui/shijieditu_1.gnp"));
			UIWindows.removeImage("/img/newui/" + WORLD_IMAGE[m_area_index] + ".gnp");
		}
	};
	
	/**
	 * 世界地图点击
	 */
	private DWListener m_lis_world = new DWListener() {
		public void OnDoubleClick() {
		}
		public void OnClick() {
			float x = m_imagebox_world.getClickX();
			float y = m_imagebox_world.getClickY();
			
			int multiple = DWGameManager.AdpaterType == DWGameManager.AD_HIGH ? 15 : 10;
			if (m_is_area) {
				int[][] points = AREA_POINT[m_area_index];
				for (int i = 0; i < points.length; i++) {
					int[] point = points[i];
					if (x >= point[0] * multiple / 10 && x <= point[0] * multiple / 10 + point[2] * multiple / 10
							&& y >= point[1] * multiple / 10 && y <= point[1] * multiple / 10 + point[3] * multiple / 10) {
						transmitHint(AREA_NAME[m_area_index][i], AREA_KEY[m_area_index][i]);
						break;
					}
				}
			} else {
				for (int i = 0; i < WORLD_POINT.length; i++) {
					int[] point = WORLD_POINT[i];
					if (x >= point[0] * multiple / 10 && x <= point[0] * multiple / 10 + point[2] * multiple / 10
							&& y >= point[1] * multiple / 10 && y <= point[1] * multiple / 10 + point[3] * multiple / 10) {
						if (WORLD_IMAGE[i] != null) {//图片不空 切图
							m_is_area = true;
							m_area_index = i;
							m_button_world.setShow(true);
							m_button_world.setTouch(true);
							m_imagebox_world.setImage(UIWindows.createImage("/img/newui/" + WORLD_IMAGE[i] + ".gnp"));
							UIWindows.removeImage("/img/newui/shijieditu_1.gnp");
						} else {
							transmitHint(WORLD_NAME[i], WORLD_KEY[i]);
						}
						break;
					}
				}
			}
		}
	};
	
	private void transmitHint(final String name, final String key) {
		if (!m_is_transit) {
			if (DWGameManager.getInstance().m_map_name.equals(name)) {
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_A, "已在当前地图,不需要传送!");
				return;
			}
			if(DWGameManager.getInstance().m_role.m_vip_lv < 1){
//				final DWMessageBox mb = new DWMessageBox("提示", "直接传送需要成为VIP用户，您是否充值?", "充值", null);
//				mb.addListener(new DWListener() {
//					public void OnDoubleClick() {
//					}
//					public void OnClick() {
//						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
//							DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte) 1, (byte) 0);
//						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
//						}
//						DWControlsManager.getInstance().removeControl(mb);
//					}
//				});
//				DWControlsManager.getInstance().addControl(mb);
				final DWMessageBox mb = new DWMessageBox("提示", "是否传送到" + name + "?", "确定", "返回");
				mb.addListener(new DWListener() {
					public void OnDoubleClick() {
					}
					public void OnClick() {
						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
							DWGameManager.getInstance().getSendMessage().sendSceneTransfer(key);
							DWControlsManager.getInstance().removeControl(mb);
						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
							DWControlsManager.getInstance().removeControl(mb);
						}
					}
				});
				DWControlsManager.getInstance().addControl(mb);
			}else{				
				final DWMessageBox mb = new DWMessageBox("提示", "是否传送到" + name + "?", "确定", "返回");
				mb.addListener(new DWListener() {
					public void OnDoubleClick() {
					}
					public void OnClick() {
						if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
							DWGameManager.getInstance().getSendMessage().sendSceneTransfer(key);
							DWControlsManager.getInstance().removeControl(mb);
						} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
							DWControlsManager.getInstance().removeControl(mb);
						}
					}
				});
				DWControlsManager.getInstance().addControl(mb);
			}
		} else {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_A, "正在传送中...");
		}
	}
	
	private void openFindPath(float x, float y) {
		UIHook.closeHook();
		DWGameManager.getInstance().m_role.doPath(new PointF(x * Scene.THUMBNAIL_ZOOM_RATIO, y * Scene.THUMBNAIL_ZOOM_RATIO));
		DWGameManager.getInstance().m_role.breakAutoAttack();
		
	}
	
	private DWExternalDraw m_ed_world = new DWExternalDraw() {
		public void externalDraw(DWGraphics g, int x, int y) {
			
		}
	};
	private DWExternalDraw m_ed_area = new DWExternalDraw() {
		public void externalDraw(DWGraphics g, int x, int y) {
			if (m_world_map != null && DWControlsManager.getInstance().contains(m_world_map)) {
				for (int i = 0; i < m_scene_npc.size(); i++) {
					SceneNPC npc = m_scene_npc.get(i);
					if ((npc.m_type == GameActorConstants.ACTOR_TYPE_GATE && m_cb_portal != null && m_cb_portal.getChecked())
							|| (npc.m_type == GameActorConstants.ACTOR_TYPE_NPC && m_cb_npc != null && m_cb_npc.getChecked())
							|| (npc.m_type == GameActorConstants.ACTOR_TYPE_MONSTER && m_cb_monster != null && m_cb_monster.getChecked())
							|| (npc.m_type == GameActorConstants.ACTOR_TYPE_GATHERING && m_cb_interaction != null && m_cb_interaction.getChecked())) {
						g.drawShadowString(npc.m_name, Tools.BLACK, Tools.WHITE, x + npc.m_x, y + npc.m_y, Tools.HCENTER_BOTTOM);
					}
				}
				Role role = DWGameManager.getInstance().m_role;
				if (role.m_vocation == 1) {
					if (role.m_sex == 1) {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_jiannan, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					} else {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_jiannv, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					}
				} else if (role.m_vocation == 2) {
					if (role.m_sex == 1) {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_wunan, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					} else {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_wunv, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					}
				} else if (role.m_vocation == 3) {
					if (role.m_sex == 1) {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_daonan, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					} else {
						g.drawBitmap(UIWindows.getInstance().m_main.m_team_daonv, x + role.m_posX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + role.m_posY / Scene.THUMBNAIL_ZOOM_RATIO, Tools.HCENTER_BOTTOM);
					}
				}
				
				int[] points = role.m_pathfinding_paths;
				if (points != null && points.length > 0) {
					SceneHandler sh = (SceneHandler)DWGameManager.getInstance().getGameHandler();
					Background background = sh.m_scene.m_bg;
					for (int i = role.m_pathfinding_index; i < points.length; i++) {
						int targetX = ((points[i] % background.m_columns) * background.m_tileW) + (background.m_tileW >> 1);
						int targetY = ((points[i] / background.m_columns) * background.m_tileH) + (background.m_tileH >> 1);
						g.setColor(Color.YELLOW);
						g.fillArc(x + targetX / Scene.THUMBNAIL_ZOOM_RATIO,
								y + targetY / Scene.THUMBNAIL_ZOOM_RATIO, 6, 6, 0, 360);
					}
				}
			}
		}
	};
	/**
	 * 读取传送时间
	 * @param dis
	 * @throws IOException
	 */
	public static void recvTransitTime(DataInputStream dis) throws IOException {
		m_transit_length = dis.readByte() * DWGameManager.FRAME_PER_SECOND;
		m_transit_message = dis.readUTF();
		m_transit_action = dis.readShort();
		m_transit_cmd = dis.readInt();
		m_transit_function = dis.readUTF();
		
		DWControlsManager.getInstance().removeOtherControl();
		
		UIWindows.getMain().setBarTotal(m_transit_message, m_transit_length);
		DWGameManager.getInstance().m_role.stay(DWGameManager.getInstance().m_role.m_direct);
		DWGameManager.getInstance().m_role.setAction(m_transit_action, true);
		m_is_transit = true;
	}
	private static int m_transit_length = 0;//倒计时总时间
	private static String m_transit_message = null;//读条信息
	public static short m_transit_action = 0;//角色动作
	public static int m_transit_cmd = 0;
	public static String m_transit_function = null;
	public static boolean m_is_transit = false;//是否开始传送读条
	
	private static CopyOnWriteArrayList<SceneNPC> m_scene_npc = new CopyOnWriteArrayList<SceneNPC>();
	public static void recvSceneMap(DataInputStream dis) throws IOException
	{
		byte size = dis.readByte();
		Tools.debugPrintln("读取场景地图NPC长度 : " + size);
		UIMap map = UIWindows.getInstance().m_map;
		if (map != null) {
			if (map.m_world_map != null) {
				map.m_world_map.destroy();
				map.m_world_map = null;
			}
		}
		m_scene_npc.clear();
		if (size > 0) {
			for (byte i = 0; i < size; i++) {
				SceneNPC npc = new SceneNPC();
				npc.m_type = dis.readByte();
				npc.m_key = dis.readUTF();
				npc.m_name = dis.readUTF();
				npc.m_status = dis.readByte();//任务状态
				npc.m_icon = dis.readByte();//功能图标
				npc.m_x = dis.readInt() / Scene.THUMBNAIL_ZOOM_RATIO;
				npc.m_y = dis.readInt() / Scene.THUMBNAIL_ZOOM_RATIO;
				m_scene_npc.add(npc);
				Tools.debugPrintln("第" + (i + 1) + "个NPC type : "
						+ npc.m_type + ", key : " + npc.m_key
						+ ", name : " + npc.m_name + ", status : " + npc.m_icon);
			}
		} else {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "当前场景无NPC!");
		}
	}
	private boolean m_is_area = false;//false在世界地图,true在区域地图中
	
	private int m_area_index = 0;//地区索引
	/**
	 * 世界地图的图片
	 */
	private final String[] WORLD_IMAGE = {"xianshandt_1", "yanluodiandt_1", "kunlundt_1",
			"changandt_1", "huangquandt_1", null, "yaochidt_1", null, "taishandt_1", "dongting_1", "guidudt_1"};
	
	/**
	 * 世界地图中的名称
	 */
	private final String[] WORLD_NAME = {"蓬莱", "阎罗殿", "昆仑", "长安", "黄泉", "凌霄殿", "瑶池", "仙缘村", "泰山", "洞庭", "丰都" };

	/**
	 * 世界地图的key
	 */
	private final String[] WORLD_KEY = {null, null, null, null, null, "lxd", null, "xins_xyc", null, null, null};
	/**
	 * 世界地图点击信息
	 */
	private final int[][] WORLD_POINT = 
	{
	{34,15,97,106},
	{25,138,123,130},
	{144,14,106,86},
	{263,78,105,98},
	{164,180,122,109},
	{426,90,111,91},
	{382,10,115,72},
	{552,13,115,91},
	{620,112,96,80},
	{544,193,106,98},
	{360,190,112,111}
	};

	private final String[][] AREA_NAME = 
	{
	//蓬莱
	{"凌虚渡", "洞虚府", "九华台", "奇兽崖", "蓬莱阁", "神木林"},
	//阎罗殿
	{"平等殿", "血污池", "无间狱", "转轮殿", "森罗狱", "阎罗殿", "生死道"},
	//昆仑
	{"西海", "凝碧林", "昆仑雪原", "玉龙村", "射日岭"},
	//长安
	{"慈恩寺", "西市", "太极宫", "渭水", "芙蓉园", "东市"},
	//黄泉
	{"点鬼台", "三途川", "鬼门关", "奈何桥", "孟婆庄", "望乡台"},
	//凌霄殿
	null,
	//瑶池
	{"通天路", "欲天台", "青鸾殿", "蟠桃园", "瑶台", "百草园", "迎真崖"},
	//仙缘村
	null,
	//泰山
	{"天齐殿", "日观峰", "岱宗坊", "碧霞祠", "明霞谷"},
	//洞庭
	{"灵虚府", "南岳庙", "湘妃祠", "洞庭山", "洞庭乡"},
	//丰都
	{"丰都府", "剥皮亭", "黑水河", "鬼市", "血市", "地藏庙"},
	};

	private final String[][] AREA_KEY = 
	{
	//蓬莱
	{"pengl_lxd", "pengl_dxf", "pengl_jht", "pengl_qsy", "pengl_plg", "pengl_sml"},
	//阎罗殿
	{"yanl_pdd", "yanl_xwc", "yanl_wjy", "yanl_zld", "yanl_sly", "yanl_yld", "yanl_ssd"},
	//昆仑
	{"kunl_xh", "kunl_nbl", "kunl_klxy", "kunl_ylc", "kunl_srl"},
	//长安
	{"changa_ces", "changa_xs", "changa_tjg", "changa_ws", "changa_fry", "changa_ds"},
	//黄泉
	{"huangq_dgt", "huangq_stc", "huangq_gmg", "huangq_nhq", "huangq_mpz", "huangq_wxt"},
	//凌霄殿
	null,
	//瑶池
	{"yaoc_ttl", "yaoc_ytt", "yaoc_qld", "yaoc_pty", "yaoc_yt", "yaoc_bcy", "yaoc_yzy"},
	//仙缘村
	null,
	//泰山
	{"tais_tqd", "tais_rgf", "tais_dzf", "tais_bxc", "tais_mxg"},
	//洞庭
	{"dongt_lxf", "dongt_nym", "dongt_xfc", "dongt_dts", "dongt_dtx"},
	//丰都
	{"fengd_fdf", "fengd_bpt", "fengd_hsh", "fengd_gs", "fengd_xs", "fengd_dzt"},
	};

	private final int[][][] AREA_POINT =
	{
	//蓬莱
	{{119,26,110,100},
	{207,128,110,120},
	{347,8,120,120},
	{358,139,120,120},
	{570,5,120,110},
	{583,135,120,120}},

	//阎罗殿
	{{49,100,110,120},
	{183,16,120,120},
	{203,156,100,130},
	{307,85,110,130},
	{423,150,110,130},
	{471,15,110,130},
	{585,81,100,150}},
	
	//昆仑
	{{52,135,110,110},
	{174,12,110,150},
	{316,112,120,150},
	{445,29,120,130},
	{568,73,110,140}},

	//长安
	{{125,154,120,130},
	{153,33,120,120},
	{319,109,120,120},
	{396,8,120,100},
	{453,160,110,120},
	{566,73,120,110}},

	//黄泉
	{{106,10,120,120},
	{136,131,110,120},
	{293,125,120,130},
	{417,18,100,110},
	{456,156,110,120},
	{558,21,110,130}},

	//凌霄殿
	null,

	//瑶池
	{{97,8,130,120},
	{155,134,120,130},
	{311,20,110,130},
	{333,155,120,130},
	{426,1,120,120},
	{541,162,120,140},
	{590,20,110,135}},

	//仙缘村
	null,

	//泰山
	{{79,15,120,120},
	{180,142,120,120},
	{348,57,120,170},
	{518,150,120,120},
	{556,17,120,120}},

	//洞庭
	{{103,25,130,110},
	{104,150,150,130},
	{359,44,130,130},
	{491,154,110,120},
	{581,22,110,120}},

	//丰都
	{{507,21,172,122},
	{540,150,171,126},
	{347,174,158,122},
	{118,176,172,112},
	{53,38,167,129},
	{252,28,183,133}},
	};
}
